package com.zareal.ymcc.fallback;

import com.zareal.ymcc.enums.GlobalErrorCode;
import com.zareal.ymcc.feign.CourseMarketFeignClient;
import com.zareal.ymcc.result.JSONResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CourseMarketFeignClientFallbackFactory implements FallbackFactory<CourseMarketFeignClient> {
    @Override
    public CourseMarketFeignClient create(Throwable throwable) {
        log.info("查询销售信息降级");
        return new CourseMarketFeignClient() {
            @Override
            public JSONResult get(Long courseId) {
                return JSONResult.error("获取销售信息熔断", GlobalErrorCode.COURSE_MARKET_IS_ERROR.getErrorMessage());
            }
        };
    }
}
